package com.morningstar.system.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.morningstar.common.result.ServiceCheckResult;
import com.morningstar.system.dao.entity.SysForm;
import com.morningstar.system.dao.mapper.SysFormMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class SysFormService extends ServiceImpl<SysFormMapper, SysForm> {

    public ServiceCheckResult checkAddAndUpdate(SysForm sysForm) {
        LambdaQueryWrapper<SysForm> checkFormNameWrapper = new LambdaQueryWrapper<SysForm>()
                .eq(SysForm::getFormName, sysForm.getFormName())
                .ne(sysForm.getFormId() != null, SysForm::getFormName, sysForm.getFormName());
        if (this.count(checkFormNameWrapper) > 0) {
            return new ServiceCheckResult(true, "表单名称已存在");
        }
        return new ServiceCheckResult(false);
    }
}
